package nnet2.net.functions;

import static java.lang.Math.tanh;

import java.security.InvalidParameterException;

public class Sigmoid implements ActivationFunction {

    private double beta;

    public Sigmoid() {
        this.beta = 1.0f;
    }

    public Sigmoid(double beta) {
        this.beta = beta;
    }

    public double getBeta() {
        return beta;
    }

    public void setBeta(double beta) {
        if (beta == 0f) {
            throw new InvalidParameterException();
        }
        this.beta = beta;
    }

    @Override
    public double f(double x) {
        return (double) tanh(beta * x);
    }

    @Override
    public double df(double x) {
        double fx = f(x);
        return beta * (1 - fx * fx);
        //return 1/(Math.cosh(x)*Math.cosh(x));
    }
}
